package com.ghost.view.pop
{
	import com.ghost.model.Global_data;
	import com.ghost.model.Object_pool;
	import com.ghost.utils.MovieClipUtil;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	/**
	 * @author ghost
	 * 所有弹出窗口的基类
	 */	

	public class Pop_base extends Sprite
	{
		public var __transitionManager:*;
		public var type:int;//0 正常  1不可拖动 有背景（其他不可点）
		public var back_mc:Sprite;//背景
		//public var extra_w:Number=64;//整个宽度-背景的宽度
		private var closing_bool:Boolean = false;//是否正在关闭
		public function Pop_base()
		{
			
		}
		/**
		 * 初始化 
		 */		
		public function init():void
		{
			var close_btn_c:* = Global_data.obj_ui_h.get("close_btn");
			if(close_btn_c!= null)
			{
				var close_btn:SimpleButton = new close_btn_c();
				this.addChild(close_btn);
				close_btn.x = this.width-78;
				close_btn.y = 47;
				close_btn.addEventListener(MouseEvent.CLICK,close_Handler);//关闭此pop
			}
			if(type==0)this.addEventListener(MouseEvent.CLICK,index_Handler);//设置此pop到最顶端
			if(back_mc)back_mc.addEventListener(MouseEvent.MOUSE_DOWN,down_Handler);//按下背景开始拖动
			if(back_mc)back_mc.addEventListener(MouseEvent.MOUSE_UP,up_Handler);//放手停止拖动
		}
		private function close_Handler(e:MouseEvent):void
		{
			closing_bool = true;
			close_all();
		}
		/**
		 *关闭此pop
		 */		
		public function close_all():void
		{
			trace(11111);
		}
		private function down_Handler(e:MouseEvent):void
		{
			trace(Global_data.stage_s_width)
			this.startDrag(false,new Rectangle(0,0,Global_data.stage_s_width,Global_data.stage_s_height));
		}
		private function up_Handler(e:MouseEvent):void
		{
			this.stopDrag();
		}
		private function index_Handler(e:MouseEvent):void
		{
			if(!closing_bool)MovieClipUtil.swapChildToTop(this.parent,this);
			else closing_bool = false;
		}
	}
}